package net.lesscoding.kafka.admin;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.Arrays;
import java.util.Properties;

import static net.lesscoding.kafka.common.Const.OS_KAFKA;

/**
 * @author eleven
 * @date 2024/7/1 14:29
 * @apiNote
 */
public class AdminTopicTest {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, OS_KAFKA);

        // 创建管理员对象
        Admin admin = Admin.create(properties);
        CreateTopicsResult topics = admin.createTopics(Arrays.asList(
                /**
                 * 创建主题需要三个参数
                 * 1. 主题名称
                 * 2. int类型分区数据
                 * 3. 主题分局副本银子数量 ：short
                 */
                new NewTopic("topicName1", 1, (short) 1),
                new NewTopic("topicName2", 1, (short) 1),
                new NewTopic("topicName3", 1, (short) 1)
        ));
        admin.close();
    }
}
